//
//  UIButton+NoHighlightState.m
//  desms
//
//  Created by gao on 2017/10/28.
//  Copyright © 2017年 e360. All rights reserved.
//

#import "UIButton+NoHighlightState.h"
#import <objc/runtime.h>

static NSString *noHighlightStateKey = @"noHighlightState";

@implementation UIButton (NoHighlightState)
+(void)load{
    
    Method originalSelector = class_getInstanceMethod([UIButton class], @selector(setHighlighted:));
    
    Method replaceSelector = class_getInstanceMethod([UIButton class], @selector(setHighlightedHook:));
    
    method_exchangeImplementations(originalSelector, replaceSelector);
    
}
-(void)setNoHighligthState:(BOOL)noHighligthState{
    objc_setAssociatedObject(self, &noHighlightStateKey, [NSNumber numberWithBool:noHighligthState], OBJC_ASSOCIATION_ASSIGN);
}
-(BOOL)noHighligthState{
    return [objc_getAssociatedObject(self, &noHighlightStateKey)boolValue];
}
-(void)setHighlightedHook:(BOOL)highlight{
    if(self.noHighligthState){
        [self setHighlightedHook:NO];
    }
    else{
        [self setHighlightedHook:highlight];
    }
}
@end
